package com.hcc.client2.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: HC
 * @Date: 2019/4/19 16:07
 * @Version 1.0
 */
@RestController
public class IndexController {

  //这里注入的restTemplate就是在com.sam.ConsumerApp中通过@Bean配置的实例
  @Autowired
  RestTemplate restTemplate;

  @RequestMapping("/hello-consumer")
  public String helloConsumer() {
    //调用hello-service服务，注意这里用的是服务名，而不是具体的ip+port
    restTemplate.getForObject("http://hello-service/hello", String.class);
    return "hello consumer finish !!!";
  }

}
